﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using élénkPróbája.extentions;
using élénkPróbája.Test.dto;
using élénkPróbája.Test.extention;

namespace élénkPróbája.Test
{
    [TestClass]
    public class CustomFailureActionTester
    {
        TestValidator validator;
        public CustomFailureActionTester()
        {
            validator = new TestValidator();
        }

        [TestMethod]
        public void Invokes_custom_action_on_failure()
        {
            bool invoked = false;
            validator.RuleFor(x => x.Name).NotNull().OnAnyFailure(x => {
                invoked = true;
            });

            validator.Validate(new Company());

            invoked.ShouldBeTrue();
        }
        [TestMethod]
        public void Passes_object_being_validated_to_action()
        {
            var company = new Company();
            Company validatedCompany = null;

            validator.RuleFor(x => x.Name).NotNull().OnAnyFailure(x => {
                validatedCompany = x;
            });

            validator.Validate(company);

            company.ShouldBeTheSameAs(validatedCompany);
        }
        [TestMethod]
        public void Does_not_invoke_action_if_validation_success()
        {
            bool invoked = false;
            validator.RuleFor(x => x.Name).NotNull().OnAnyFailure(x => {
                invoked = true;
            });
            validator.Validate(new Company() { Name = "foo" });
            invoked.ShouldBeFalse();
        }

    }
}
